<?php

namespace Biz\service;

use Biz\model\MailTemplate as mMailTemplate;
use Biz\model\ShopAuth as mShopAuth;
use Biz\tools\Mail as toolMail;
use Doraemon\model\Phone;
use Doraemon\model\Phone as mPhone;
use Doraemon\service\Member\PhoneCrypto;
use Doraemon\tools\Log as tLog;
use Doraemon\tools\Sms as tSms;
use hhz\constant\basic\findPhoneScene;

/**
 * @deprecated
 */
class MessageSend
{
    const SHOP_PHONE_DECRYPT_MIRROR = 'magic_mirror_decrypt_shop_checkin';

    public static function sendEmail($email, $tag, $params = [])
    {
        try {
            $res = mMailTemplate::getMessage($tag, $params);

            if (empty($res))
                return false;


            $result = toolMail::send($email, $res['title'], $res['content']);

            tLog::info('商家层面邮件发送日志', ['email' => $email, 'tag' => $tag, 'res' => $res]);

            return $result;
        } catch (Exception $e) {
            tLog::warning('发送邮件失败', ['email' => $email, 'tag' => $tag, 'res' => $res, 'error' => $e->getMessage()]);
        }
    }

    public static function sendShopEmailByUid($uid, $tag, $params = [])
    {
        $shopUser = mShopAuth::getByUid($uid);

        if (empty($shopUser))
            return false;

        return self::sendEmail($shopUser['email'], $tag, $params);
    }

    public static function sendShopSmsByUid($uid, $tpl, $params = [])
    {
        $phone = Phone::getDecryptPhoneByUid($uid, findPhoneScene::SHOP_INFO_PHONE);
        if (empty($phone))
            return false;

        tSms::sendTplMsg($phone, $tpl, $params);
    }

}